package cn.iocoder.yudao.module.hs.controller.admin.sap;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.hs.controller.admin.sap.vo.MaterialSyncVO;
import cn.iocoder.yudao.module.hs.controller.admin.sap.vo.RawMaterialOrderSyncVO;
import cn.iocoder.yudao.module.hs.controller.admin.sap.vo.ShipOrderSyncVO;
import cn.iocoder.yudao.module.hs.service.sap.SapDataSyncService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - SAP数据同步")
@RestController
@RequestMapping("/hs/sap/data")
@Validated
public class SAPDataSyncController {

    @Resource
    private SapDataSyncService sapDataSyncService;

    /**
     * 同步物料相关信息
     * truncate hs_material;
     * truncate hs_material_box;
     * truncate hs_tray;
     */
    @PostMapping("/material/sync")
    @Operation(summary = "同步物料相关信息")
    public CommonResult<Boolean> syncMaterial(@Valid @RequestBody List<MaterialSyncVO> materialSyncVOS) {
        sapDataSyncService.syncMaterial(materialSyncVOS);
        return success(true);
    }

    /**
     * 同步出库单相关信息
     * 清空数据
     * truncate hs_ship_order;
     * truncate hs_ship_order_detail;
     */
    @PostMapping("/shipOrder/sync")
    @Operation(summary = "同步出库单相关信息")
    public CommonResult<Boolean> syncShipOrder(@Valid @RequestBody ShipOrderSyncVO shipOrderSyncVO) {
        sapDataSyncService.syncShipOrder(shipOrderSyncVO);
        return success(true);
    }

    @PostMapping("/rawMaterialOrder/sync")
    @Operation(summary = "同步领料单相关信息")
    public CommonResult<Boolean> syncRawMaterialOrder(@Valid @RequestBody List<RawMaterialOrderSyncVO> rawMaterialOrderSyncVOS) {
        sapDataSyncService.syncRawMaterialOrder(rawMaterialOrderSyncVOS);
        return success(true);
    }
}
